package org.bw.bookstore.book.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.bw.bookstore.book.service.OrderService;
import org.bw.bookstore.common.entity.TbOrderRecord;
import org.bw.bookstore.common.entity.TbPayRecord;
import org.bw.bookstore.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @program:wisdom_bookstore
 * @description:订单控制层
 * @author:钟乐
 * @create:2020-10-22 10:54
 **/

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("orderRecord")
@Api(tags = "接口-订单管理微服务")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping(value = "checkBookSingleNoPay")
    @ApiOperation(value = "返回未付款书籍详情", notes = "返回未付款书籍详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "rfids", value = "书籍单品的RFID", dataType = "String", required = true)
    })
    /**
     　　* TODO zl-createOrderRecord--返回未付款书籍详情
     　　* @Param [orderRecord]
     　　* @return com.bw.common.utils.ResponseResult
     　　* @author 钟乐
     　　* @date 2020/10/22 11:17
     　　*/
    public ResponseResult checkBookSingleNoPay(String rfids){
        return orderService.checkBookSingleNoPay(rfids);
    }

    @PostMapping(value = "createOrderRecord")
    @ApiOperation(value = "生成订单记录和订单商品", notes = "生成订单记录和订单商品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "支付人", dataType = "String", required = true),
            @ApiImplicitParam(name = "rfids", value = "书籍单品的RFID", dataType = "String", required = true)
    })
    /**
    　　* TODO zl-createOrderRecord--生成订单记录
    　　* @Param [orderRecord]
    　　* @return com.bw.common.utils.ResponseResult
    　　* @author 钟乐
    　　* @date 2020/10/22 11:17
    　　*/
    public ResponseResult createOrderRecord(@ApiIgnore TbOrderRecord orderRecord, String rfids){
        return orderService.createOrderRecord(orderRecord,rfids);
    }

    @PostMapping(value = "createOrderRecord1")
    @ApiOperation(value = "生成订单记录和订单商品", notes = "生成订单记录和订单商品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "支付人", dataType = "String", required = true),
            @ApiImplicitParam(name = "code", value = "书籍的code", dataType = "String", required = true),
            @ApiImplicitParam(name = "num", value = "书籍数量", dataType = "Integer", required = true)
    })
    /**
     　　* TODO zl-createOrderRecord1--线上选择好书籍与数量然后生成订单记录
     　　* @Param [orderRecord]
     　　* @return com.bw.common.utils.ResponseResult
     　　* @author 钟乐
     　　* @date 2020/10/22 11:17
     　　*/
    public ResponseResult createOrderRecord1(@ApiIgnore TbOrderRecord orderRecord,String code,Integer num){
        return orderService.createOrderRecord1(orderRecord,code,num);
    }

    @PostMapping(value = "findOneOrderRecordOnline")
    @ApiOperation(value = "用户查看自己的订单记录", notes = "用户查看自己的订单记录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code", dataType = "String", required = true)
    })
    /**
     　　* TODO zl-findOneOrderRecordOnline-查看单个订单记录
     　　* @Param [orderRecordId]
     　　* @return com.bw.common.utils.ResponseResult
     　　* @author 钟乐
     　　* @date 2020/10/22 11:19
     　　*/
    public ResponseResult findOneOrderRecordOnline(@RequestParam("userInfoCode") String userInfoCode){
        return orderService.findOneOrderRecordOnline(userInfoCode);
    }

    @PostMapping(value = "createPayRecord")
    @ApiOperation(value = "生成支付记录", notes = "生成支付记录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "payStatus", value = "支付方式", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "orderRecordCode", value = "支付订单code", dataType = "String", required = true),
            @ApiImplicitParam(name = "userInfoCode", value = "用户code", dataType = "String", required = true)
    })
    /**
     　　* TODO zl-createPayRecord-生成支付记录
     　　* @Param [payRecord]
     　　* @return com.bw.common.utils.ResponseResult
     　　* @author 钟乐
     　　* @date 2020/10/22 11:19
     　　*/
    public ResponseResult createPayRecord(@ApiIgnore TbPayRecord payRecord){
        return orderService.createPayRecord(payRecord);
    }

    /**
     * TODO 钟乐 根据用户code查找支付记录
     * @Author: 钟乐
     * @Date: 2020/10/21 19:29
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("findPayRecordById")
    @ApiOperation(value="根据用户code查找支付记录", notes="根据用户code查找支付记录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code",dataType = "String",required = true)
    })
    public ResponseResult findPayRecordById(@RequestParam("userInfoCode") String userInfoCode){
        return orderService.findPayRecordById(userInfoCode);
    }

    @PostMapping(value = "updateBookSingleStatus")
    @ApiOperation(value = "修改书籍单品状态", notes = "修改书籍单品状态")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "rfids", value = "rfids", dataType = "String", required = true)
    })
    /**
    　　* TODO  zl-updateBookSingleStatus-修改书籍单品状态
    　　* @Param [rfid]
    　　* @return com.bw.common.utils.ResponseResult
    　　* @author 钟乐
    　　* @date 2020/10/22 11:36
    　　*/
    public ResponseResult updateBookSingleStatus(@RequestParam("rfids")String rfids){
        return orderService.updateBookSingleStatus(rfids);
    }


    @PostMapping(value = "cancelOrderRecord")
    @ApiOperation(value = "取消订单", notes = "取消订单")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code", dataType = "String", required = true),
            @ApiImplicitParam(name = "orderRecordId", value = "订单id", dataType = "integer", required = true)
    })
    /**
    　　* TODO  zl-cancelPayRecord-取消订单
    　　* @Param [userInfoCode, orderRecordCord]
    　　* @return com.bw.common.utils.ResponseResult
    　　* @author 钟乐
    　　* @date 2020/10/23 9:58
    　　*/
    public ResponseResult cancelOrderRecord(@RequestParam("userInfoCode") String userInfoCode,
                                            @RequestParam("orderRecordId") Integer orderRecordId){
        return orderService.cancelOrderRecord(userInfoCode,orderRecordId);
    }


    @PostMapping(value = "weChatPay")
    @ApiOperation(value = "微信支付", notes = "微信支付")
    /**
    　　* TODO  weChatPay--微信支付
    　　* @Param []
    　　* @return com.bw.common.utils.ResponseResult
    　　* @author 钟乐
    　　* @date 2020/10/23 15:36
    　　*/
    public ResponseResult weChatPay(){
        return orderService.weChatPay();
    }

    @PostMapping(value = "appPayment")
    @ApiOperation(value = "App支付", notes = "App支付")
    /**
     　　* TODO  appPayment--App支付
     　　* @Param []
     　　* @return com.bw.common.utils.ResponseResult
     　　* @author 钟乐
     　　* @date 2020/10/23 15:36
     　　*/
    public ResponseResult appPayment(){
        return orderService.appPayment();
    }
}
